package com.example.springcloud.demo.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.fastjson.JSON;
import com.example.springcloud.demo.entity.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("/v1/demo")
public class DemoController {

    @GetMapping("sentinel-webflux")
    @SentinelResource(value = "用户下单", fallbackClass = SentinelComponent.class, fallback = "demoSentinelWebFluxError")
    public Mono<String> demoSentinelWebFlux() {
        User user = new User();
        user.setUsername("liukui");
        return Mono.just(JSON.toJSONString(user));
    }


    @GetMapping("sentinel-web")
    public String demoSentinelWeb() {
        return "请求成功\n";
    }
}
